package com.coco.bargain.controller;

import com.coco.bargain.pojo.TbBargainItem;
import com.coco.bargain.service.BargainItemService;
import com.coco.bargain.vo.BargainItemTableSearchVo;
import com.coco.bargain.vo.BargainUserVo;
import com.coco.common.result.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author HanSama
 * @date 2021年07月22日 20:24
 */
@RestController
@RequestMapping("/bargain/item")
public class BargainItemController {

    @Autowired
    private BargainItemService bargainItemService;

    /**
     * 列表
     * @author HanSama
     * @date 2021/7/25 18:30
     * @param bargainItemTableSearchVo
     * @return com.coco.common.result.ResultData
     */
    @PostMapping("/search")
    public ResultData search(@RequestBody BargainItemTableSearchVo bargainItemTableSearchVo){
        return bargainItemService.seach(bargainItemTableSearchVo);
    }

    /**
     * 添加
     * @author HanSama
     * @date 2021/7/25 18:30
     * @param tbBargainItem
     */
    @RequestMapping("/add")
    public void add(@RequestBody TbBargainItem tbBargainItem){
        System.out.println(tbBargainItem);
        bargainItemService.add(tbBargainItem);
    }

    /**
     * 修改
     * @author HanSama
     * @date 2021/7/25 18:31
     * @param tbBargainItem
     */
    @RequestMapping("/update")
    public void update(@RequestBody TbBargainItem tbBargainItem){
        System.out.println(tbBargainItem);
        bargainItemService.update(tbBargainItem);
    }


    /**
     * 通过ID获取
     * @author HanSama
     * @date 2021/7/25 18:31
     * @param id
     * @return com.coco.bargain.pojo.TbBargainItem
     */
    @GetMapping("/findById/{id}")
    public TbBargainItem findById(@PathVariable("id") Long id) {
        return bargainItemService.findById(id);
    }

    /**
     * 逻辑删除
     * @author HanSama
     * @date 2021/7/25 18:32
     * @param id
     */
    @DeleteMapping("/deleteById/{id}")
    public void deleteById(@PathVariable("id") Long id){
        bargainItemService.deleteById(id);
    }

    @GetMapping("/seeDetails/{id}")
    public List<BargainUserVo> seeDetails(@PathVariable("id") Long id){

        return bargainItemService.seeDetails(id);
    }

}
